using System;

namespace PingPong.Generic.Helpers
{

	public static class EventHelper
	{
		#region Methods

		/// <summary>
		/// Fires the event if the given event handler has established subscribers.
		/// </summary>
		/// <returns><c>true</c>, if event was fired, <c>false</c> otherwise.</returns>
		/// <param name="event">Event.</param>
		/// <param name="sender">Sender.</param>
		/// <param name="eventArgs">Event arguments.</param>
		/// <typeparam name="T">The 1st type parameter.</typeparam>
		public static bool SafeFireEvent<T>(EventHandler<T> @event, object sender, T eventArgs) 
			where T : EventArgs
		{
			if(@event != null)
			{
				@event(sender,eventArgs);
				return true;
			}

			return false;
		}

		#endregion
	}
}

